1. Summary

In this task, I will be working with spatial data regarding the 2008 California DFW oil spill. The analysis will include an interactive tmap of the oil spill sites, and a static choropleth map for which color of each county depends on the count of inland oil spill events.

2. Read in the Spatial Data

ca_oil_spill_sf <- read_sf(here('data/oil_spill/ds394.shp')) %>% 
  clean_names()

ca_counties_sf <- read_sf(here('data/ca_counties/CA_Counties_TIGER2016.shp')) 

ca_subset_sf <- ca_counties_sf %>% 
  clean_names() %>% 
  select(county_name = name, land_area = aland)

head(ca_oil_spill_sf)
## Simple feature collection with 6 features and 12 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -131184.3 ymin: -592855.8 xmax: 506070.5 ymax: -29107.6
## Projected CRS: NAD83 / California Albers
## # A tibble: 6 x 13
##   dfgcontrol oesnumber dateofinci timeofinci inlandmari specificlo  water
##   <chr>      <chr>     <date>     <chr>      <chr>      <chr>       <chr>
## 1 08FG1315   08-2566   2008-04-04 1100       Marine     Marine      Yes  
## 2 08FG0798   08-1391   2008-02-17 0632       Inland     Fresh Water Yes  
## 3 08FG3355   08-7520   2008-10-16 1737       Inland     Fresh Water Yes  
## 4 08FG3531   08-7979   2008-10-30 1700       Inland     Fresh Water Yes  
## 5 08FG2139   08-4440   2008-06-22 0449       Inland     Fresh Water Yes  
## 6 08FG3543   08-8018   2008-11-02 0830       Inland     Fresh Water Yes  
## # ... with 6 more variables: waterway <chr>, localecity <chr>,
## #   localecoun <chr>, latitude <dbl>, longitude <dbl>, geometry <POINT [m]>
head(ca_subset_sf)
## Simple feature collection with 6 features and 2 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -13565690 ymin: 3862173 xmax: -13096340 ymax: 4833572
## Projected CRS: WGS 84 / Pseudo-Mercator
## # A tibble: 6 x 3
##   county_name     land_area                                             geometry
##   <chr>               <dbl>                                   <MULTIPOLYGON [m]>
## 1 Sierra         2468694587 (((-13431320 4821511, -13431313 4821520, -13431300 ~
## 2 Sacramento     2499183617 (((-13490651 4680832, -13490511 4680817, -13490465 ~
## 3 Santa Barbara  7084000598 (((-13423117 4042044, -13423158 4043249, -13422800 ~
## 4 Calaveras      2641820834 (((-13428575 4627725, -13428535 4627889, -13428535 ~
## 5 Ventura        4773390489 (((-13317854 3931602, -13317828 3932624, -13317686 ~
## 6 Los Angeles   10510651024 (((-13210018 3958856, -13210085 3959984, -13209920 ~

3. Create Interactive tmap

ca_oil_spill_sf <-
  st_transform(ca_oil_spill_sf,
               st_crs(ca_subset_sf))

tmap_mode(mode = 'view')

tm_shape(ca_subset_sf) +
  tm_fill('county_name', legend.show = FALSE) +
  tm_shape(ca_oil_spill_sf) +
  tm_dots() 

4. Choropleth Map of Oil Spill by County

### Wrangle to find sesbania observations per county

oil_county_sf <- ca_subset_sf %>% 
  st_join(ca_oil_spill_sf)

head(oil_county_sf)
## Simple feature collection with 6 features and 14 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -13565690 ymin: 4582029 xmax: -13358430 ymax: 4833572
## Projected CRS: WGS 84 / Pseudo-Mercator
## # A tibble: 6 x 15
##   county_name  land_area                           geometry dfgcontrol oesnumber
##   <chr>            <dbl>                 <MULTIPOLYGON [m]> <chr>      <chr>    
## 1 Sierra      2468694587 (((-13431320 4821511, -13431313 4~ 08FG3273   08-7293  
## 2 Sacramento  2499183617 (((-13490651 4680832, -13490511 4~ 08FG1864   08-3780  
## 3 Sacramento  2499183617 (((-13490651 4680832, -13490511 4~ 08FG0788   08-1373  
## 4 Sacramento  2499183617 (((-13490651 4680832, -13490511 4~ 08FG0682   08-1146  
## 5 Sacramento  2499183617 (((-13490651 4680832, -13490511 4~ 08FG2238   08-4873  
## 6 Sacramento  2499183617 (((-13490651 4680832, -13490511 4~ 08FG2285   08-4970  
## # ... with 10 more variables: dateofinci <date>, timeofinci <chr>,
## #   inlandmari <chr>, specificlo <chr>, water <chr>, waterway <chr>,
## #   localecity <chr>, localecoun <chr>, latitude <dbl>, longitude <dbl>
oil_counts_sf <- oil_county_sf %>% 
  group_by(county_name) %>% 
  summarize(oil_count = sum(!is.na(dfgcontrol)))

head(oil_counts_sf)
## Simple feature collection with 6 features and 2 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -13668380 ymin: 4502606 xmax: -13307390 ymax: 4888059
## Projected CRS: WGS 84 / Pseudo-Mercator
## # A tibble: 6 x 3
##   county_name oil_count                                                 geometry
##   <chr>           <int>                                       <MULTIPOLYGON [m]>
## 1 Alameda           188 (((-13612247 4538150, -13612347 4538291, -13612423 4538~
## 2 Alpine              1 (((-13366504 4678946, -13366493 4678954, -13366468 4678~
## 3 Amador              8 (((-13472698 4647652, -13472698 4647677, -13472698 4647~
## 4 Butte              11 (((-13565005 4798394, -13564992 4798529, -13565000 4798~
## 5 Calaveras           7 (((-13428575 4627725, -13428535 4627889, -13428535 4628~
## 6 Colusa              4 (((-13589905 4781178, -13589881 4781178, -13589804 4781~
ggplot(data = oil_counts_sf) +
  geom_sf(aes(fill = oil_count),
          color = 'white', size = 0.1) +
  scale_fill_gradientn(colors = c('lightgrey', 'orange', 'red')) +
  theme_minimal() +
  labs(fill = 'Oil Spill Total by County')

For this task, read in the spatial data, and create a professionally formatted and prepared HTML (showing all of your code directly or making it available with code-folding) from an .Rmd in which you: Make an exploratory interactive map in tmap showing the location of oil spill events included in the data. Make a finalized static choropleth map in ggplot in which the fill color for each county depends on the count of inland oil spill events by county for the 2008 oil spill data ALSO INCLUDE OVERVIEW